#include "StdAfx.h"
#include "ConfigReader.h"
#include <iostream>
#include <fstream>

ConfigReader::ConfigReader(void)
{
	LoadConfig("data/default_config.ini");
}


ConfigReader::~ConfigReader(void)
{
}

void ConfigReader::LoadConfig(char *filename)
{
	std::ifstream config;
	config.open(filename);
	
	std::string line;
	if (config.is_open())
	{
		while (!config.eof())
		{
			getline(config, line);
			if (line.length() > 0 && line[0] != '#') // ignore comments
			{
				int index = line.find_first_of(':');
				std::string param = line.substr(0, index);
				std::string value = line.substr(index+1, line.length());

				if (param.compare("ServerIP") == 0) m_ServerIP = value;
				if (param.compare("ServerPort") == 0) m_ServerPort = atoi(value.c_str());
				if (param.compare("MsgDelay") == 0) m_MsgDelay = atoi(value.c_str());
				if (param.compare("PlayerType") == 0) m_PlayerType = atoi(value.c_str());
				if (param.compare("MovSpeed") == 0) m_PlayerMovSpd = atof(value.c_str());
				if (param.compare("TurnSpeed") == 0) m_PlayerTurnSpd = atof(value.c_str());
				if (param.compare("DR_BASE") == 0) m_fDR_BASE = atof(value.c_str());
				if (param.compare("DR_HEIGHT") == 0) m_fDR_HEIGHT = atof(value.c_str());
				if (param.compare("COLLISION_RADIUS") == 0) m_fCollisionRadius = atof(value.c_str());
			}
		}
	}
	config.close();
}